home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / graphics / pstex / fopenp.c < prev    next >
C/C++ Source or Header  |  1992-01-27  |  2KB  |  108 lines

  1. /*
  2.  * Fopenp function.
  3.  *
  4.  * Neil Hunt (Neil%Teleos.com@ai.sri.com)
  5.  *
  6.  * Copyright (c) 1989 Teleos Research, Inc 1989.
  7.  * Copyright (c) 1988 Schlumberger Technologies, Inc 1988.
  8.  *
  9.  * Anyone can use this software in any manner they choose,
  10.  * including modification and redistribution, provided they make
  11.  * no charge for it, and these conditions remain unchanged.
  12.  *
  13.  * This program is distributed as is, with all faults (if any), and
  14.  * without any warranty. No author or distributor accepts responsibility
  15.  * to anyone for the consequences of using it, or for whether it serves any
  16.  * particular purpose at all, or any other reason.
  17.  *
  18.  * $Log:    fopenp.c,v $
  19.  * Revision 1.1  90/04/17  13:05:43  kakiuchi
  20.  * Initial revision
  21.  * 
  22.  * Revision 1.1  89/02/10  18:40:39  neil
  23.  * Initial revision
  24.  * 
  25.  * Copied from newlib.
  26.  * Revision 1.2  88/09/19  18:29:53  hunt
  27.  * Fixed typo.
  28.  * 
  29.  * Revision 1.1  88/09/19  15:52:47  hunt
  30.  * Initial revision
  31.  */
  32.  
  33. static char rcsid[] = "$Revision: 1.1 $";
  34.  
  35. #include <stdio.h>
  36. #include <string.h>
  37.  
  38. #ifdef MSDOS
  39. #define PATHNAMEDELIMITER '\\'
  40. #define PATHNAMEDELIMITERSTR "\\"
  41. #else
  42. #define PATHNAMEDELIMITER '/'
  43. #define PATHNAMEDELIMITERSTR "/"
  44. #endif
  45.  
  46. #ifdef MSDOS
  47. #define ENVDELIMITER ';'
  48. #else
  49. #define ENVDELIMITER ':'
  50. #endif
  51.  
  52.  
  53. FILE *
  54. fopenp(char *path, char *name, char *fullname, char *mode)
  55. {
  56.     register char *p;
  57.     register FILE *f;
  58.  
  59. #ifdef MSDOS
  60.     if((*name == PATHNAMEDELIMITER) || (*(name+1) == ':'))
  61. #else
  62.     if(*name == PATHNAMEDELIMITER)
  63. #endif
  64.     {
  65.         strcpy(fullname, name);
  66.         return fopen(fullname, mode);
  67.     }
  68.  
  69.     while(*path)
  70.     {
  71.         /*
  72.          * Copy first/next path prefix to fullname.
  73.          * Skip over the ':'.
  74.          * Add the '/'.
  75.          * Concat the filename.
  76.          */
  77.         for(p = fullname; *path != '\0'; )
  78.         {
  79. #ifdef MSDOS
  80.             if (*path == ENVDELIMITER)
  81. #else
  82.             if (*path == ENVDELIMITER || *path == ';')
  83. #endif
  84.             {
  85.                 path++;
  86.                 break;
  87.             }
  88.             else
  89.                 *p++ = *path++;
  90.         }
  91. #ifdef MSDOS
  92.         if (*(p-1) != PATHNAMEDELIMITER) *p++ = PATHNAMEDELIMITER;
  93. #else
  94.         *p++ = PATHNAMEDELIMITER;
  95. #endif
  96.         strcpy(p, name);
  97.         /*
  98.          * Try to open the file.
  99.          */
  100.         if((f = fopen(fullname, mode)) != (FILE *)NULL)
  101.             return f;
  102.     }
  103.  
  104.     return (FILE *)NULL;
  105. }
  106.  
  107.  
  108.